package com.xm.service.background;

import com.xm.dao.background.OrdersDao;
import com.xm.entity.Orders;
import com.xm.entity.Page;
import com.xm.exception.SqlErrorException;


/**
 * 订单
 * @author 康文程
 * @date 2024-1-9 下午 03:54
 */
public class OrdersService {
    private final OrdersDao dao = new OrdersDao();
    /**
     * 分页查询所有订单，并关联查询address表
     *
     * @param pageNo   页码
     * @param pageSize 每页数量
     * @return 分页结果
     * @throws SqlErrorException SQL执行异常
     */
    public Page<Orders> getAllOrdersWithAddressByPage(int pageNo, int pageSize,String sort,String state,String nameorId) throws SqlErrorException {
        return dao.getAllOrdersWithAddressByPage(pageNo, pageSize,sort,state,nameorId);
    }
    /**
     * 根据订单ID查询订单
     *
     * @param orderId 订单ID
     * @return 订单对象
     * @throws SqlErrorException SQL执行异常
     */
    public Orders getOrderByOrderId(String orderId) throws SqlErrorException {
        return dao.getOrderByOrderId(orderId);
    }
    /**
     * 根据订单编号修改warehouse_id
     *
     * @param orderId     订单编号
     * @param warehouseId 仓库编号
     * @return 是否修改成功
     * @throws SqlErrorException SQL执行异常
     */
    public boolean updateWarehouseIdByOrderId(String orderId, int warehouseId) throws SqlErrorException {
        return dao.updateWarehouseIdByOrderId(orderId, warehouseId);
    }
    /**
     * 根据订单Id修改logistics_companies_id、logistics_station_id、orders_status、mode_of_delivery
     *
     * @param orderId              订单ID
     * @param logisticsCompaniesId 物流公司ID
     * @param logisticsStationId   物流站点ID
     * @param ordersStatus         订单状态
     * @param modeOfDelivery       配送方式
     * @return 是否修改成功
     * @throws SqlErrorException SQL执行异常
     */
    public boolean updateOrderDetails(String orderId, int logisticsCompaniesId, int logisticsStationId, int ordersStatus, int modeOfDelivery) throws SqlErrorException {
        return dao.updateOrderDetails(orderId,logisticsCompaniesId,logisticsStationId,ordersStatus,modeOfDelivery);
    }
    /**
     * 根据订单ID修改订单状态
     *
     * @param orderId      订单ID
     * @param ordersStatus 订单状态
     * @return 是否修改成功
     * @throws SqlErrorException SQL执行异常
     */
    public boolean updateOrderStatusByOrderId(String orderId, Integer ordersStatus) throws SqlErrorException {
        return dao.updateOrderStatusByOrderId(orderId, ordersStatus);
    }
    /**
     * 分页查询所有订单，并关联查询address表
     *
     * @param pageNo   页码
     * @param pageSize 每页数量
     * @param sort     排序方式
     * @param state    订单状态
     * @param nameOrId 地址名称或订单ID
     * @return 分页结果
     * @throws SqlErrorException SQL执行异常
     */
    public Page<Orders> getAllOrdersByPage(int pageNo, int pageSize, String sort, String state, String nameOrId) throws SqlErrorException {
        return dao.getAllOrdersByPage(pageNo, pageSize, sort, state, nameOrId);
    }
    /**
     * 查询orders_status为9的订单数量
     * @param status 订单状态
     * @return 订单数量
     * @throws SqlErrorException SQL执行异常
     */
    public int getOrdersCountByStatusNine(Integer status) throws SqlErrorException {
        return dao.getOrdersCountByStatusNine(status);
    }
}
